<?php

	include_once('../sys/sys.php');
	//header('Content-Type: text/html; charset=utf-8');
	$action = $_GET['action'];
	$tid = $_GET['id'];
	
	if(!is_numeric($tid) || $tid < 0){
		show_normal_mesR('TAG ID错误','TAG ID错误','TAG查询');
	}
	//获取这本的名字
	$name = $DB->build_and_exec_query(array(
			'select' 	=> 'name',
			'from'		=> '7nstories',
			'where'		=>	'id=' . $tid,
	));
	$name = trim(mb_convert_encoding($name['name'],"GB2312","UTF-8"));
	//开始获取该ID下的图片
	$DB->build_query(array(
			'select' 	=> 'text',
			'from'		=> '7nchapters',
			'where'		=>	'sid=' . $tid,
	));
	$qid = $DB->exec_query();
	$pics = '';
	$i = 1;
	while ($row = $DB->fetch_row($qid)) {
		$pics .= $row['text'] . "\r\n\r\n\r\n";
		
// 		file_put_contents("d:\\tmp\\tmp" . $i . ".txt", $pics);
// 		$i++;
	}
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Content-Type: text/plain; charset=GB2312");
// 	header("Content-Type: text/html; charset=GB2312");
	header("Content-Disposition: attachment;filename=\"" . $name. ".txt\"");
	echo mb_convert_encoding($pics,"GB2312","UTF-8");

	
?>